package uit.bus;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class ThongTinTuyen extends ListActivity {
	public ArrayList<OrderTTT> listOrder = null;
	public OrderTTTAddapter addapter;
	public DBAdapter db;
	public Cursor mycursor;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listtttuyen);

		listOrder = new ArrayList<OrderTTT>();
		addapter = new OrderTTTAddapter(this, R.layout.row_thongtintuyen,
				listOrder);
		setListAdapter(addapter);
		db = new DBAdapter(this);
		db.open();
		mycursor = db.getListTuyen();
		getListOrder(mycursor);

	}

	public void getListOrder(Cursor cursor) {
		OrderTTT order;
		listOrder = new ArrayList<OrderTTT>();
		
		for (cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()) {
			order = new OrderTTT();
			order.setMatuyen(cursor.getInt(0));
			order.setTentuyen(cursor.getString(1));
			listOrder.add(order);
		}
		db.close();
		if (listOrder != null && listOrder.size() > 0) {
			for (int i = 0; i < listOrder.size(); i++) {
				addapter.add(listOrder.get(i));
			}
		}
		addapter.notifyDataSetChanged();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		
		Intent i = new Intent("uit.bus.TUYENCT");
		Bundle extra = new Bundle();
		extra.putInt("matuyen", listOrder.get(position).getMatuyen());
		i.putExtras(extra);
		startActivity(i);
		
	}

}
